package com.itwelkin.ssm.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Customer {
    private String id;
    private String cname;
    private Integer gender;
    private Date birthday;
    private Float balance;
    private String love;
    private Integer clevel;
    private Date regTime;

    @Override
    public String toString() {
        return "Customer{" +
                "id='" + id + '\'' +
                ", cname='" + cname + '\'' +
                ", gender=" + gender +
                ", birthday=" + birthday +
                ", balance=" + balance +
                ", love='" + love + '\'' +
                ", clevel=" + clevel +
                ", regTime=" + regTime +
                '}';
    }
    public int getAge() {
        LocalDate birthDate = birthday.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDate currentDate = LocalDate.now();
        return Period.between(birthDate, currentDate).getYears();
    }
}
